package com.gitee.wsl.func.transform.sample

import com.gitee.wsl.base.Objects
import com.gitee.wsl.func.transform.Transformer


/**
 * Transformer implementation that chains the specified transformers together.
 *
 *
 * The input object is passed to the first transformer. The transformed result
 * is passed to the second transformer and so on.
 *
 *
 * @param <T> the type of the input and result to the function.
 * @since 3.0
</T> */
//class ChainedTransformer<T> private constructor(clone: Boolean, transformers: Array<Transformer<in T?, out T?>?>?) :
//    Transformer<T?, T?>, Serializable {
//    /** The transformers to call in turn  */
//    private val iTransformers: Array<Transformer<in T?, out T?>>
//
//    /**
//     * Hidden constructor for the use by the static factory methods.
//     *
//     * @param clone  if `true` the input argument will be cloned
//     * @param transformers  the transformers to chain, no nulls
//     */
//    init {
//        iTransformers = if (clone) FunctorUtils.copy(transformers) else transformers
//    }
//
//    /**
//     * Constructor that performs no validation.
//     * Use `chainedTransformer` if you want that.
//     *
//     * @param transformers  the transformers to chain, copied, no nulls
//     */
//    constructor(vararg transformers: Transformer<in T?, out T?>?) : this(true, transformers)
//
//    val transformers: Array<Transformer<in T?, out T?>>
//        /**
//         * Gets the transformers.
//         *
//         * @return a copy of the transformers
//         * @since 3.1
//         */
//        get() = FunctorUtils.copy(iTransformers)
//
//    /**
//     * Transforms the input to result via each decorated transformer
//     *
//     * @param object  the input object passed to the first transformer
//     * @return the transformed result
//     */
//    public override fun transform(`object`: T?): T? {
//        var `object` = `object`
//        for (iTransformer in iTransformers) {
//            `object` = iTransformer.apply(`object`)
//        }
//        return `object`
//    }
//
//    companion object {
//        private val EMPTY_TRANSFORMER_ARRAY: Array<Transformer?> = arrayOf<Transformer?>()
//
//        /** Serial version UID  */
//        private const val serialVersionUID = 3514945074733160196L
//
//        /**
//         * Create a new Transformer that calls each transformer in turn, passing the
//         * result into the next transformer. The ordering is that of the iterator()
//         * method on the collection.
//         *
//         * @param <T>  the object type
//         * @param transformers  a collection of transformers to chain
//         * @return the `chained` transformer
//         * @throws NullPointerException if the transformers collection is null
//         * @throws NullPointerException if any transformer in the collection is null
//        </T> */
//        fun <T> chainedTransformer(
//            transformers: Collection<out Transformer<in T?, out T?>?>,
//        ): Transformer<T?, T?>? {
//            Objects.requireNonNull(transformers, "transformers")
//            if (transformers.isEmpty()) {
//                return NOPTransformer.< T > nopTransformer < T ? > ()
//            }
//            // convert to array like this to guarantee iterator() ordering
//            val cmds: Array<Transformer<T?, T?>?>? = transformers.toArray(EMPTY_TRANSFORMER_ARRAY)
//            FunctorUtils.validate(cmds)
//            return ChainedTransformer<Any?>(false, cmds)
//        }
//
//        /**
//         * Factory method that performs validation and copies the parameter array.
//         *
//         * @param <T>  the object type
//         * @param transformers  the transformers to chain, copied, no nulls
//         * @return the `chained` transformer
//         * @throws NullPointerException if the transformers array is null
//         * @throws NullPointerException if any transformer in the array is null
//        </T> */
//        fun <T> chainedTransformer(vararg transformers: Transformer<in T?, out T?>?): Transformer<T?, T?>? {
//            FunctorUtils.validate(transformers)
//            if (transformers.size == 0) {
//                return NOPTransformer.< T > nopTransformer < T ? > ()
//            }
//            return ChainedTransformer<Any?>(*transformers)
//        }
//    }
//}